package com.example.questionsystem.modules.qu.service.util;

import org.apache.poi.xwpf.usermodel.*;

public class FileUtil {
    public static String extractTextFromDocx(XWPFDocument doc) {
        StringBuilder content = new StringBuilder();
        
        // 提取段落文本
        for (XWPFParagraph p : doc.getParagraphs()) {
            String text = p.getText().trim();
            if (!text.isEmpty()) {
                content.append(text).append("\n");
            }
        }
        
        // 提取表格文本
        for (XWPFTable table : doc.getTables()) {
            for (XWPFTableRow row : table.getRows()) {
                for (XWPFTableCell cell : row.getTableCells()) {
                    for (XWPFParagraph p : cell.getParagraphs()) {
                        String text = p.getText().trim();
                        if (!text.isEmpty()) {
                            content.append(text).append("\n");
                        }
                    }
                }
            }
        }
        
        return content.toString();
    }
}